from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from basic.database import init_db
from routers import *
from contextlib import asynccontextmanager


@asynccontextmanager
async def lifespan(app: FastAPI):
    # 启动逻辑
    print("Application is starting up...")
    # 在这里添加你的启动逻辑
    await init_db()
    yield
    # 关闭逻辑
    print("Application is shutting down...")


app = FastAPI(
    title="FastAPI示例应用",
    description="这是一个FastAPI示例应用",
    version="1.0.0",
    lifespan=lifespan,
)

# 配置CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

app.include_router(file_router)
app.include_router(repo_router)
app.include_router(entry_router)
app.include_router(s3_router)
app.include_router(version_router)


if __name__ == "__main__":
    routers = app.routes
    for router in routers:
        print(router.path, router.methods)
